<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>注册界面</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="layui/css/layui.css" media="all">
  	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="icon" href="favicon.ico">
  <link rel="stylesheet" href="css/admin.css" media="all">
  <link rel="stylesheet" href="css/login.css" media="all">
</head>
<body>

  <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
      <div class="layadmin-user-login-box layadmin-user-login-header">
        <h2>注册界面</h2>
      </div>
      <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
      
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-nickname"></label>
          <input type="text" name="uname" id="LAY-user-login-nickname" lay-verify="nickname" placeholder="账号" class="layui-input">
        </div>
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
          <input type="password" name="passwd" id="LAY-user-login-passwd" lay-verify="pass" placeholder="密码" class="layui-input">
        </div>
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-repass"></label>
          <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required|repass" placeholder="确认密码" class="layui-input">
        </div>
          <div class="layui-form-item">
          	<label class="layadmin-user-login-icon layui-icon layui-icon-cellphone" for="LAY-user-login-cellphone"></label>
          	<input type="text" name="email" id="LAY-user-login-email" lay-verify="email" placeholder="邮箱" class="layui-input">
        </div>
        <div class="layui-form-item">
          <div class="layui-row">
          </div>
        </div>
        <div class="layui-form-item">
          <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-reg-submit">注 册</button>
        </div>
        <div class="layui-trans layui-form-item layadmin-user-login-other">
          <label>社交账号注册</label>
          <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
          <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
          <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>        
          <a href="login.jsp" class="layadmin-user-jump-change layadmin-link layui-hide-xs">用已有帐号登入</a>
          <a href="login.jsp" class="layadmin-user-jump-change layadmin-link layui-hide-sm layui-show-xs-inline-block">登入</a>
        </div>
      </div>	
    </div>
  </div>

  <script type="text/javascript" src="layui/layui.js"></script>  
  <script>
  layui.use(['form', 'jquery'], function(){
	  	$ = layui.jquery
		,layer = layui.layer  
	    ,form = layui.form
	    ,router = layui.router()
	    ,search = router.search;

  	form.render();

  //自定义验证规则
    form.verify({
    	username : function(value, item){  
     		 var message=''; 
     		  $.ajax({          
     			  url: "${path}/action/register/exist",       
     			  type: "post",                
     			  async: false,                   
     			  data: {          				
     				username:value                
     				  },                  
     			  dataType: "json",       
     			  success: function (data) {   
     				  if(data.success){
     					  message = '用户名已经存在！' 
     				  	} 
     				}   
     			});     
     		  return message;
     		 }
    
      ,pass: [/(.+){6,12}$/, '密码必须6到12位'] 
      ,repass: function(value){
      	var passwdValue = $('input[name=passwd]').val();
      	if(value != passwdValue){
      	return '两次输入的密码不一致!';
      	}
      	} 
    });
    
    //监听提交
    form.on('submit(LAY-user-reg-submit)', function(data){	 
      $.ajax({          
  			  url: "${path}/action/register/index",       
  			  type: "post",                
  			  async: false,                   
  			  data: data.field,                  
  			  dataType: "json",       
  			  success: function (data) {
  				  if(data.success){ 
  					  layer.msg("注册成功,即将跳转登陆", {icon:1, shade:[0.5, '#000000'], shadeClose:true,time:2000}, function(text, index){
  					  	window.location.href = "${path}/login.jsp"
  					  });
  				  	} else{ 
  				    	layer.msg('该用户已被注册', {icon:5, shade:[0.5, '#000000'], shadeClose:true,time:2000}); 
  				  	}
  				}   
  			});  
      return false;
    });
  });
  </script>
</body>
</html>